package biz

import (
    "context"

    "github.com/go-kratos/kratos/v2/log"
    "mall/app/order/internal/domain"
)

type OrderRepo interface {
    Create(ctx context.Context, order *domain.Order) (*domain.Order, error)
    List(ctx context.Context) ([]*domain.Order, error)
    Detail(ctx context.Context, OrderNo string) (*domain.Order, error)
}

type Transaction interface {
    ExecTx(context.Context, func(context.Context) error) error
}

type OrderUseCase struct {
    repo OrderRepo
    tx   Transaction
    log  *log.Helper
}

func NewOrderUseCase(repo OrderRepo, tx Transaction, logger log.Logger) *OrderUseCase {
    return &OrderUseCase{
        repo: repo,
        tx:   tx,
        log:  log.NewHelper(log.With(logger, "module", "use-case/order")),
    }
}

func (uc *OrderUseCase) Create(ctx context.Context, order *domain.Order) (*domain.Order, error) {
    return uc.repo.Create(ctx, order)
}
